package com.heima.wemedia.controller.v1;

import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.WmNewsDto;
import com.heima.model.wemedia.dtos.WmNewsPageReqDto;
import com.heima.wemedia.service.WmNewsService;
import net.sourceforge.tess4j.TesseractException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {


    @Autowired
    private WmNewsService wmNewsService;

    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDto dto){
        return  wmNewsService.findAll(dto);
    }
    @PostMapping("/submit")
    public ResponseResult submitNews(@RequestBody WmNewsDto dto) throws TesseractException, IOException {
        return  wmNewsService.submitNews(dto);
    }
    //查看文章详情/one/6233
    @GetMapping("/one/{id}")
    public ResponseResult findOne(@PathVariable("id") Integer id){
        return  wmNewsService.findOne(id);
    }
    /** 上下架
     *   url:  /down_or_up
     *   post: enable=0,id=1
     */
    @PostMapping("/down_or_up")
    public ResponseResult downOrUp(@RequestBody WmNewsDto dto){
        return  wmNewsService.downOrUp(dto);
    }
    /**
     * 删除文章
     * url:del_news/6227
     * get
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delNews(@PathVariable("id") Integer id){
        return  wmNewsService.delNews(id);
    }
    //查询文章列表/api/v1/news/list_vo
    @PostMapping("/list_vo")
    public ResponseResult findListVo(@RequestBody WmNewsDto dto){
        return  wmNewsService.findListVo(dto);
    }

    //查询文章详情/api/v1/news/one_vo/{id}
    @GetMapping("/one_vo/{id}")
    public ResponseResult findOneVo(@PathVariable("id") Integer id){
        return  wmNewsService.findOneVo(id);
    }
    //审核失败/api/v1/news/auth_fail
    @PostMapping("/auth_fail")
    public ResponseResult authFail(@RequestBody WmNewsDto dto){
        return  wmNewsService.authFail(dto);
    }
    //审核成功/api/v1/news/auth_pass
    @PostMapping("/auth_pass")
    public ResponseResult authPass(@RequestBody WmNewsDto dto){
        return  wmNewsService.authPass(dto);
    }
}